package demo.view.api.enterprise;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.FileUtils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import util.HttpClientUtil;


public class ViewSignatureToken {
	
	private static String appKey = "cAwut4VATycNMq17NZeFUD63pe83l2OJ";
    private static String appSecrty = "3BAlrfr7lW8kwlCMfo1dXS8Syn5q5qjS";
    private static String baseUrl = "http://smp-test.szitrus.com.cn/smp-view-api";
    private static String api = "/api/enterprise/view/signature/token";	
    
	public static void main(String[] args) throws IOException {
		String url = baseUrl.concat(api);
		 // 请求参数
        Map<String, String> params = new HashMap<>();
        //params.put("file_url", "test");
        params.put("file_data", Base64.encodeBase64String(FileUtils.readFileToByteArray(new File("D:/smp_temp/test.pdf"))));//base64
       
        params.put("file_extension", "pdf");
        params.put("doc_number", "TEST-GXHT-20200506-000003");
        params.put("doc_title", "购销合同");
        params.put("description", "购销合同签署");
        params.put("operator", "gaoym");
//        params.put("official_seals", "['1','2']");
        params.put("comments", "[{\"title\":\"签署意见\",\"content\":\"同意<br>物料在合同签署后，尽快落实到位日期。\"}]");
        params.put("callback_url", "http://cabackurl");
        params.put("return_url", "http://reurnurl");
        params.put("options", "{\"show_personal\":\"yes\" , \"show_official\":\"yes\" , \"show_timestamp\":\"yes\", \"qrcode\":\"yes\"}");
        
        String resStr =  HttpClientUtil.getResponse(url, params, appKey, appSecrty);
	    JSONObject resJson = JSON.parseObject(resStr);
	    System.out.println(resJson);
	    String token = resJson.getJSONObject("data").getString("token");
	    String redirect_url = baseUrl.concat("/?token=").concat(token);
	    
	    System.out.println(redirect_url);
	    
	}
}
